package ui.fragment;

import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.v4.app.DialogFragment;
import android.support.v7.app.AlertDialog;

/**
 * Created by 10153 on 2018/8/5.
 */

public class EnsureResetBTFragment extends DialogFragment{
    
    public interface OnDialogCallBack {
        void onSureReset(boolean isSure);
    }
    
    private OnDialogCallBack mCallback;
    
    @Override
    public void onAttach(Context context) {
        super.onAttach(context);
        if(!(getActivity() instanceof OnDialogCallBack))
            throw new IllegalStateException("activity should implement CallBack!");
        mCallback = (OnDialogCallBack)getActivity();
    }
    
    @Override
    public void onDetach() {
        super.onDetach();
        mCallback = null;
    }
    
    @NonNull
    @Override
    public Dialog onCreateDialog(Bundle savedInstanceState) {
        return new AlertDialog.Builder(getActivity())
                .setMessage("已存在一个蓝牙连接，是否重置？")
                .setPositiveButton("确定", new DialogInterface.OnClickListener() {
    
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        mCallback.onSureReset(true);
                    }
                })
                .setNegativeButton("取消", new DialogInterface.OnClickListener() {
    
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        mCallback.onSureReset(false);
                    }
                })
                .create();
    }
}
